#!/bin/bash

# AI Daily - 简化版前后端服务启动脚本
echo "🚀 Starting AI Daily Services..."

# 获取脚本所在目录
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BACKEND_DIR="$SCRIPT_DIR/backend"
FRONTEND_DIR="$SCRIPT_DIR/frontend"

# 启动后端服务
cd "$BACKEND_DIR"
if [ ! -d "venv" ]; then
    python3 -m venv venv
fi
source venv/bin/activate
pip install -r requirements.txt
nohup uvicorn main:app --host 0.0.0.0 --port 8001 --reload > backend.log 2>&1 &
echo $! > backend.pid

# 启动前端服务
cd "$FRONTEND_DIR"
if [ ! -d "node_modules" ]; then
    npm install
fi
nohup npm run dev > ../frontend.log 2>&1 &
echo $! > ../frontend.pid

echo "🎉 All services started!"
echo "Frontend: http://localhost:3000"
echo "Backend: http://localhost:8001"